package com.pointwest.pls.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.pointwest.pls.constant.DBConstant;

public class ConfigManager {
	
	private static ConfigManager instance = null;

	/**
	 * private constructor of class for singleton
	 */
	private ConfigManager() {
		

	}
	
	/**creates connection to database
	 * @return current connection
	 * @throws SQLException
	 * @throws Exception
	 * @throws ClassNotFoundException
	 */
	public Connection getConnection () throws SQLException, Exception, ClassNotFoundException {
		Connection currentConn = null;

		
			try {
				Class.forName(DBConstant.DRIVER);
				currentConn = DriverManager.getConnection(DBConstant.URL, DBConstant.SQL_USERNAME,  DBConstant.SQL_PASSWORD);
				
			} catch (SQLException sqlExc) {
				throw sqlExc;
			} catch (ClassNotFoundException classExc){
				throw classExc;
			} catch (Exception e){
				throw e;
			}		

		return currentConn;
	}
	
	/**for singleton
	 * @return current instance of class
	 */
	public static ConfigManager getInstance() {
		
		if (instance == null) {
			instance = new ConfigManager();
		}
		
		return instance;
	}
	

}